// function groupModelsByType(models) {
//     return models.reduce((acc, model) => {
//         const { modelType } = model;
//         if (!acc[modelType]) {
//             acc[modelType] = [];
//         }
//         acc[modelType].push(model);
//         return acc;
//     }, {});
// }

function es5_groupModelsByType(models) {
    var acc = {};
    models.forEach(function (model) {
        var modelType = model.modelType;
        if (!acc[modelType]) {
            acc[modelType] = [];
        }
        acc[modelType].push(model);
    });
    return acc;
}


// ES5 兼容的数组查找工具函数
function es5_find(array, callback) {
    for (var i = 0; i < array.length; i++) {
        if (callback(array[i], i, array)) {
            return array[i];
        }
    }
    return undefined;
}


// ES5 兼容的 sleep 函数
function es5_sleep(ms) {
    return new Promise(function (resolve) {
        setTimeout(resolve, ms);
    });
}

// 获取uuid
function getUUID() {
    var t = new Date().getTime();
    return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (u) {
        var e = (t + Math.random() * 16) % 16 | 0;
        return t = Math.floor(t / 16), (u === "x" ? e : e & 3 | 8).toString(16)
    })
}

// 获取sessionId
function getSessionId(agentCode, uniStorage) {
    var sessionId = uniStorage.getItem('_sessionId_' + agentCode) || ''
    if (sessionId) return sessionId
    var uuid = getUUID()
    uniStorage.setItem('_sessionId_' + agentCode, uuid)
    return uuid
}